package com.springcloud.alibabanacosconfig.mq.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/23 14:18
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/23
 * @Modify marker：
 **/
@Service
@Slf4j
public class CommonMqService {
    @Autowired
    RabbitTemplate template;
    @Autowired
    Environment env;
    public void sendRobbingMsgV2(String mobile){
        template.setExchange(env.getProperty("user.order.exchange.name"));
        template.setRoutingKey(env.getProperty("user.order.routing.key.name"));
        Message message = null;
        try {
            message = MessageBuilder.withBody(mobile.getBytes("UTF-8")).setDeliveryMode(MessageDeliveryMode.PERSISTENT).build();
        } catch (UnsupportedEncodingException e) {
            log.error("发送抢单信息入列 发生异常：mobile={}",mobile);
        }
        template.send(message);
    }
}
